﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH;
using QLBH.DTO;
using QLBH.Model.Controller;
using QLBH.DataModel;

namespace Module.Category
{
    public partial class CategoryUI : ViewBase
    {
        
        public CategoryUI()
            :base()
        {
            InitializeComponent();
        }

        private void buttonCustomer_Click(object sender, EventArgs e)
        {
            CustomerManagement cusManagement = new CustomerManagement();

            DisplayView(cusManagement);
        }

        private void buttonProvider_Click(object sender, EventArgs e)
        {
            ProviderManagement provMag = new ProviderManagement();

            DisplayView(provMag);
        }

        private void buttonUnit_Click(object sender, EventArgs e)
        {
            CalculateUnitManagement calManag = new CalculateUnitManagement();

            DisplayView(calManag);
        }

        private void buttonProductGroup_Click(object sender, EventArgs e)
        {
            ProductCatagoryManagement procateManag = new ProductCatagoryManagement();
            DisplayView(procateManag);
        }
        private void DisplayView(UserControl view)
        {
            tableLayoutPanel3.Controls.Clear();

            tableLayoutPanel3.Controls.Add(view);
        }

        private void buttonProduct_Click(object sender, EventArgs e)
        {
            ProductManagement productMan = new ProductManagement();
            DisplayView(productMan);
        }

        private void buttonDepartment_Click(object sender, EventArgs e)
        {
            DeptManagement deptmanage = new DeptManagement();
            DisplayView(deptmanage);
        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {
            RegisterShopInformation regisShopInfo = new RegisterShopInformation();
            CuaHang currentShopEntity=ShopController.Instance.GetAll().FirstOrDefault();
            if (currentShopEntity==null)
            {
                //Register new information
                regisShopInfo.DialogType = eDialogType.DL_ADD;
            } 
            else
            {
                regisShopInfo.DialogType = eDialogType.DL_EDIT;
                regisShopInfo.NewShop = currentShopEntity.ToDTO();
            }
            if (regisShopInfo.ShowDialog()==DialogResult.OK)
            {
                UpdateFeatureStatus();
            }
            
        }

        private void CategoryUI_Load(object sender, EventArgs e)
        {
            UpdateFeatureStatus();
        }
        private void UpdateFeatureStatus()
        {
            //update department feature
            CuaHang currentShop = ShopController.Instance.GetAll().FirstOrDefault();
            if (currentShop == null)
            {
                buttonDepartment.Enabled = false;
            }
            else
            {
                buttonDepartment.Enabled = true;
            }
        }

        private void buttonStaff_Click(object sender, EventArgs e)
        {
            StaffManagement staffManagement = new StaffManagement();
            DisplayView(staffManagement);
        }
    }
}
